package com.audaque.springboot.foshanupload.web.spidemo.controller;

import com.audaque.springboot.foshanupload.web.spidemo.loader.service.impl.AwesomeScriptEngineFactory;
import com.audaque.springboot.foshanupload.web.spidemo.loader.service.impl.ServiceLoader1ServiceImpl;
import com.audaque.springboot.foshanupload.web.spidemo.loader.service.impl.ServiceLoader3ServiceImpl;
import com.audaque.springboot.foshanupload.web.spidemo.loader.service.impl.ServiceLoader4ServiceImpl;
import com.audaque.springboot.foshanupload.web.spidemo.loader.service.inface.ServiceLoaderService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ServiceLoader;

/**
 * @author wangyan01
 */


@RestController
@RequestMapping("serviceLoader")
public class ServiceLoaderController {

    @Resource
    private ServiceLoader1ServiceImpl serviceLoader1ServiceImpl;

    @Resource
    private ServiceLoader3ServiceImpl serviceLoader3ServiceImpl;
    @Resource
    private ServiceLoader4ServiceImpl serviceLoader4ServiceImpl;


    //@Resource
    //private ServiceLoader5ServiceImpl serviceLoader5ServiceImpl;


    @GetMapping("loadPrint2")
    public void loadPrin2( ) throws Exception {
        ServiceLoader<ServiceLoaderService> services =
                ServiceLoader.load(ServiceLoaderService.class);
        // 测试输出结果，展示实现接口已加载
        for (ServiceLoaderService service : services) {
            service.print();
        };
    }

    @GetMapping("loadPrint1")
    public void loadPrin1( ) throws Exception {
        serviceLoader1ServiceImpl.print();
    }


    @GetMapping("loadPrint3")
    public void loadPrin3( ) throws Exception {
        serviceLoader3ServiceImpl.print();
    }


    @GetMapping("loadPrint4")
    public void loadPrin4( ) throws Exception {
        serviceLoader4ServiceImpl.print();
    }

/*

    @GetMapping("loadPrint5")
    public void loadPrin5( ) throws Exception {
        serviceLoader5ServiceImpl.print();
    }
*/


}
